home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / sun4c.md / machFPUGlue.c < prev    next >
C/C++ Source or Header  |  1991-03-15  |  3KB  |  160 lines

  1. /* 
  2.  * machFPUGlue.c --
  3.  *
  4.  *    Routines that emulate the SunOS routines called by the
  5.  *    SunOS floating point simulator for SPARC.
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/kernel/mach/sun4.md/RCS/machFPUGlue.c,v 9.2 90/10/12 17:43:18 mendel Exp $ SPRITE (Berkeley)";
  19. #endif /* not lint */
  20.  
  21. /*
  22.  * Too much of the sun fpu stuff just won't lint.
  23.  */
  24. #ifndef lint
  25.  
  26. #include "sys/types.h"
  27. #include "fpu_simulator.h"
  28. #include "vm.h"
  29.  
  30.  
  31. /*
  32.  *----------------------------------------------------------------------
  33.  *
  34.  * fuword --
  35.  *
  36.  *    Read a word from the user's address space.
  37.  *
  38.  * Results:
  39.  *    The word read or -1 if read fails.
  40.  *
  41.  * Side effects:
  42.  *    None.
  43.  *
  44.  *----------------------------------------------------------------------
  45.  */
  46.  
  47. int
  48. fuword(address)
  49.     caddr_t address;
  50. {
  51.     ReturnStatus status;
  52.     int        value;
  53.     status = Vm_CopyIn(sizeof(int), (Address) address, (Address) &value);
  54.  
  55.      return (status == SUCCESS) ? value : -1;
  56.  
  57. }
  58.  
  59.  
  60. /*
  61.  *----------------------------------------------------------------------
  62.  *
  63.  * fubyte --
  64.  *
  65.  *    Read a byte from the user's address space.
  66.  *
  67.  * Results:
  68.  *    The byte read or -1 if read fails.
  69.  *
  70.  * Side effects:
  71.  *    None.
  72.  *
  73.  *----------------------------------------------------------------------
  74.  */
  75.  
  76. int
  77. fubyte(address)
  78.     caddr_t address;
  79. {
  80.     ReturnStatus status;
  81.     unsigned char    value;
  82.     status = Vm_CopyIn(sizeof(char), (Address) address, (Address) &value);
  83.  
  84.      return (status == SUCCESS) ? value : -1;
  85.  
  86. }
  87.  
  88.  
  89. /*
  90.  *----------------------------------------------------------------------
  91.  *
  92.  * suword --
  93.  *
  94.  *    Store a word into the user's address space.
  95.  *
  96.  * Results:
  97.  *    The 0 if SUCCESS or -1 if write fails.
  98.  *
  99.  * Side effects:
  100.  *    None.
  101.  *
  102.  *----------------------------------------------------------------------
  103.  */
  104.  
  105. int
  106. suword(address,value)
  107.     caddr_t address;
  108.     int    value;
  109. {
  110.     ReturnStatus status;
  111.     status = Vm_CopyOut(sizeof(int), (Address) &value, (Address) address);
  112.  
  113.      return (status == SUCCESS) ? 0 : -1;
  114.  
  115. }
  116.  
  117. #include <sun4/fpu/globals.h>
  118.  
  119. void
  120. MachFPU_Emulate(processID, instAddr, userRegsPtr, curWinPtr)
  121.     int        processID;
  122.     Address    instAddr;
  123.     Mach_RegState     *userRegsPtr;
  124.     Mach_RegWindow    *curWinPtr;
  125. {
  126.     union {
  127.         int        i;
  128.         fp_inst_type    inst;
  129.     }        kluge;
  130.     enum ftt_type result;
  131.  
  132.     fptrapaddr = (char *) instAddr;    /* bad inst addr in case we trap */
  133.     _fp_current_pfregs = userRegsPtr;
  134.     result = fpu_simulator(instAddr, (fsr_type *) & (userRegsPtr->fsr));
  135.     switch (result) {
  136.     case ftt_none:
  137.     break;
  138.     case ftt_ieee:
  139.     (void) Sig_Send(SIG_ARITH_FAULT, SIG_ILL_INST_CODE, processID, FALSE,
  140.         (Address)0);
  141.     break;
  142.     case ftt_unimplemented:
  143.     (void) Sig_Send(SIG_ILL_INST, SIG_ILL_INST_CODE, processID, FALSE,
  144.         (Address)0);
  145.     break;
  146.     case ftt_alignment:
  147.     (void) Sig_Send(SIG_ADDR_FAULT, SIG_ADDR_ERROR, processID,FALSE,
  148.         (Address)0);
  149.     break;
  150.     case ftt_fault:
  151.     (void) Sig_Send(SIG_ADDR_FAULT, SIG_ACCESS_VIOL, processID, FALSE,
  152.         (Address)0);
  153.     case ftt_7:
  154.     default:
  155.     break;
  156.     }
  157. }
  158.  
  159. #endif /* lint */
  160.